package com.aitao.beans;

/**
 * 异常发生在代码中的位置
 *
 * @Company QAX
 * @Author : admin
 * @Create : 2022/1/10 17:40
 */
public class MarkPoint {
    /**
     * 文件名
     */
    private String filename;
    /**
     * 行号
     */
    private int lineNumber;

    public MarkPoint() {

    }

    public MarkPoint(StackTraceElement stackTraceElement) {
        this.filename = stackTraceElement.getFileName();
        this.lineNumber = stackTraceElement.getLineNumber();
    }

    public MarkPoint(String filename, int lineNumber) {
        this.filename = filename;
        this.lineNumber = lineNumber;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        if (filename != null && !filename.isEmpty()) {
            builder.append(filename);
            if (lineNumber != 0) {
                builder.append(":").append(lineNumber);
            }
            builder.append(": ");
        }
        return builder.toString();
    }
}
